<template>
  <div>
    <h1>
      当前的值：{{ $store.state.count }} -
      {{ $store.getters.oddOrEven }}
    </h1>
    <select v-model="val">
      <option :value="1">1</option>
      <option :value="2">2</option>
      <option :value="3">3</option>
    </select>
    <button @click="handleIncrement">+</button>
    <button @click="handleDecrement">-</button>
    <button @click="handleIncrementIfOdd">如果是奇数就加</button>
    <button @click="handleIncrementAsync">延迟1s加</button>
  </div>
</template>

<script>
export default {
  name: "App",
  data() {
    return {
      val: 1,
    };
  },
  methods: {
    handleIncrement() {
      this.$store.dispatch("increment", this.val);
    },
    handleDecrement() {
      this.$store.dispatch("decrement", this.val);
    },
    handleIncrementIfOdd() {
      // if (this.$store.state.count % 2 === 1) {
      //   this.handleIncrement();
      // }
      // if (this.$store.state.count & 1) {
      //   this.handleIncrement();
      // }
      this.$store.dispatch("incrementIfOdd", this.val);
    },
    handleIncrementAsync() {
      this.$store.dispatch("incrementAsync", this.val);
    },
  },
};
</script>

<style></style>
